package com.prs.crm.action.taskmanager;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;

import com.prs.crm.domain.taskmanager.ReceiveState;
import com.prs.crm.service.taskmanager.ReceiveStateService;

public class ReceiveStateAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private String serCode;
	private ReceiveState receiveState;
	private ReceiveStateService receiveStateService;
	public String getSerCode() {
		return serCode;
	}
	public void setSerCode(String serCode) {
		this.serCode = serCode;
	}
	public ReceiveState getReceiveState() {
		return receiveState;
	}
	public void setReceiveState(ReceiveState receiveState) {
		this.receiveState = receiveState;
	}
	public ReceiveStateService getReceiveStateService() {
		return receiveStateService;
	}
	public void setReceiveStateService(ReceiveStateService receiveStateService) {
		this.receiveStateService = receiveStateService;
	}
	
	@Action("editReceiveState")
	public String editReceiveState(){
		this.receiveState=this.getReceiveStateService().getReceiveState(serCode);
		return SUCCESS;
	}
	@Action(value="saveReceiveState",results={
			@Result(name="success",type="redirect",location="editReceiveState?serCode=${receiveState.getType()}"),
			@Result(name="error",type="chain",location="editReceiveState?serCode=${receiveState.getType()}")
	})
	public String saveReceiveState(){
		ReceiveState rs=this.getReceiveStateService().getReceiveState("rs01");
		if(rs==null){
			rs=new ReceiveState();
			rs.setType("rs01");
			rs.setState(receiveState.getState());
			this.getReceiveStateService().save(rs);
		}else{
			this.getReceiveStateService().submit(rs);
		}
		receiveState=rs;
		return SUCCESS;
	}
}
